C
C    Copyright (C) 1996  University of Washington, U.S.A.
C
C    Author:   Donald E. Marshall
C
C   This program is free software; you can redistribute it and/or modify
C   it under the terms of the GNU General Public License as published by
C   the Free Software Foundation; either version 1, or (at your option)
C   any later version.
C
C   This program is distributed in the hope that it will be useful,
C   but WITHOUT ANY WARRANTY; without even the implied warranty of
C   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
C   GNU General Public License for more details.
C
C   You should have received a copy of the GNU General Public License
C   along with this program; if not, write to the Free Software
C   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
C
C
C   polygon.f adds additional data points between the vertices. This 
C   program is to be run *after* zipper. It outputs only those 
C   prevertices corresponding to the original data points, eliminating 
C   those corresponding to points generated by polygon.f.
C
C   input:  index.dat  file with indices of original data points
C                      (input to polygon.f)
C           poly.pre   preimage of poly.dat
C   output: orig.pre   preimage of original data poitns
C
C
C   program origpre
      implicit double precision(a-h,o-y),integer*4(i-n),complex*16(z)
c  As written, this program is limited to 10000 (original) vertices
      dimension x(100002),y(100002),jindex(10002)
      character*55 filenm
   99 format(2g25.15)
      open(1,file='./output/poly.pre',status='old')
      do 1 j=1,100001
          read(1,*,end=50)x(j),y(j)
    1 continue
      write(*,*)' Too many prevertices. Increase dimension and'
      write(*,*)' recompile.'
      stop
   50 continue 
      open(2,file='./output/index.dat',status='old')
      do 2 k=1,10001
         read(2,*,end=51)jindex(k)
    2 continue
      write(*,*)' Too many prevertices. Increase dimension and'
      write(*,*)' recompile.'
      stop
   51 continue 
      n=k-1
      open(3,file='./output/orig.pre',status='unknown')
      do 3 m=1,n
         write(3,99)x(jindex(m)),y(jindex(m))
    3 continue
      stop
      end
